﻿/**	plane.hpp
 *	----	Create Time Stamp	--2007-09-15 13:46:55--
 *-----------------------------------------------------------------------------
 *	Mean	:
 *	Author	:Nick Shallery	(nicknide@gmail.com)
 *	Version	:1.0.1.1	(2007-09-15 13:46:55)
 *-----------------------------------------------------------------------------
**/	/*YOU HAVE ALL LEFT WITH THIS CODE WHILE YOU KEEP COMMENT IN EVERY COPY.*/


#if			!defined(__LOLIX__SOLA__PLANE__K_IN_G__)
#define		__LOLIX__SOLA__PLANE__K_IN_G__


#if			!defined(__LOLIX__LOLI_X_CFG__K_IN_G__)
	#include	"../lolix_cfg.h"
#endif	//	!defined(__LOLIX__LOLI_X_CFG__K_IN_G__)

#if			LOLIX_CFG__PER_CHECK_FILE_CHUNK_SPACE
	#if			!defined(__LOLIX__SOLA__VECTOR__NICK__K_IN_G__)
		#include	"./vector.h"
	#endif		//	!defined(__LOLIX__SOLA__VECTOR__NICK__K_IN_G__)
	#if			!defined(__LOLIX__SOLA__TRIANGLE__K_IN_G__)
		#include	"./triangle.hpp"
	#endif	//	!defined(__LOLIX__SOLA__TRIANGLE__K_IN_G__)

#else	//	LOLIX_CFG__PER_CHECK_FILE_CHUNK_SPACE
	#include	"./vector.h"
	#include	"./triangle.hpp"

#endif	//	LOLIX_CFG__PER_CHECK_FILE_CHUNK_SPACE


namespace lolix{namespace sola{
	template<typename _Ty>
	class plane
	{
		typedef	plane<_Ty>	this_type;
	public:
		typedef	_Ty				element_type;
		typedef	vector<3, _Ty>	normal_type;

		LOLIX_INLINE_CALL	plane<_Ty>(void){}
		template<typename _Tn, typename _Td>
		LOLIX_INLINE_CALL	plane<_Ty>(const vector<3, _Tn>& n, const _Td& d)
			: N(n), D(d){}
		template<typename	_To>
		LOLIX_INLINE_CALL	plane<_Ty>(const plane<_To>& o)
			: N(o.N), D(o.D){}
		template<typename _Tt>
		LOLIX_INLINE_CALL	plane<_Ty>(const triangle<_Tt>& o)
			{ operator()(o); }

		template<typename _Tt>
		LOLIX_INLINE_CALL	this_type&	operator()(const triangle<_Tt>& o)
			{
			normal_type a(o.v[1]-o.v[0]);
			normal_type	b(o.v[2]-o.v[1]);
			n = a.cross(b);
			d = -o.v[1].dot(n);
			return *this;
			}

		//this_type&	normalize(void)
		//	{
		//	normal_type nn(n);
		//	n.normalize();
		//	}

		normal_type		n;	//	nml
		element_type	d;	//	D = -dot(P, N);
	};
}}

#endif	//	!defined(__LOLIX__SOLA__PLANE__K_IN_G__)

